<template>
	<view class="container">
		<view class="swiper-tab dis-flex box-align-center flex-y-center">
			<block v-for="item in tabList" :key="item.value">
				<view class="swiper-tab-item " :class="{ on: dataType == item.value }" :data-current="item.value" @tap="swichNav">{{ item.text }}</view>
			</block>
		</view>
		<!-- 订单列表 -->
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :height="swiperHeight + 'px'" top="80rpx">
			<view class="widget-list b-f" v-if="list.length">
				<view class="widget__detail" v-for="(item,index) in list" :key="item.order_master.order_no">
					<view class="detail__row dis-flex flex-x-between">
						<view class="detail__left f-24">订单号：{{ item.order_master.order_no }}</view>
						<view class="detail__right f-24 c-violet">{{ item.order_master.state_text }}</view>
					</view>
					<view class="detail__row m-top10 dis-flex flex-x-between">
						<view class="detail__left dis-flex flex-y-center">
							<view class="user-avatar"><image :src="item.user.avatarUrl"></image></view>
							<view class="user-info dis-flex flex-dir-column flex-x-center">
								<view class="user-nickName f-28">{{ item.user.nickName }}</view>
								<view class="user-time f-24 c-80">{{ item.order_type.text }}：￥{{ item.order_price }}</view>
							</view>
						</view>
						<view class="detail__right dis-flex flex-dir-column flex-x-center flex-y-center">
							<view class="detail__money t-r col-m">
								<text class="f-26">+</text>
								<text class="f-28" v-if="item.first_user_id == userInfo.user_id">{{ item.first_money }}</text>
								<text class="f-28" v-if="item.second_user_id == userInfo.user_id">{{ item.second_money }}</text>
								<text class="f-28" v-if="item.third_user_id == userInfo.user_id">{{ item.third_money }}</text>
							</view>
							<view class="detail__time f-22 c-80">{{ item.create_time }}</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
import Tools from '@/utils/Tools.js';
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';
export default {
	mixins: [MescrollMixin],
	data() {
		return {
			dataType: -1,
			swiperHeight: null,
			list: [],
			tabList: [
				{
					value: -1,
					text: '全部'
				},
				{
					value: 0,
					text: '未结算'
				},
				{
					value: 1,
					text: '已结算'
				}
			]
		};
	},
	onLoad() {
		this.setSwiperHeight();
	},
	onShow() {},
	methods: {
		/**
		 * 设置swiper的高度
		 */
		setSwiperHeight() {
			// 获取系统信息(拿到屏幕宽度)
			let systemInfo = wx.getSystemInfoSync();
			let tapHeight = uni.upx2px(80); // tap高度
			this.swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
		},
		upCallback(mescroll) {
			this.$u.api.getDealerOrderList(this.dataType, mescroll.num).then(res => {
				// 创建页面数据
				if (mescroll.num == 1) {
					this.list = res.data.list.data;
				} else {
					this.list.push(...res.data.list.data);
				}
				this.mescroll.endBySize(res.data.list.data.length, res.data.list.total);
			});
		},
		/**
		 * 点击tab切换
		 */
		swichNav(e) {
			this.dataType = e.target.dataset.current;
			this.$nextTick(() => {
				this.mescroll.resetUpScroll( true )
			});
		}
	}
};
</script>

<style>
page {
	background: #fff;
}

.c-violet {
	color: #786cff;
}

.c-80 {
	color: #808080;
}

/* 选项卡 */

.swiper-tab {
	text-align: center;
	height: 80rpx;
	background-color: #fff;
	border-bottom: 1px solid #eee;
	position: fixed;
	width: 750rpx;
	z-index: 100;
}

.swiper-tab .swiper-tab-item {
	width: 33.333333%;
	height: 100%;
	font-size: 28rpx;
	color: #777;
	display: flex;
	justify-content: center;
	align-items: center;
	box-sizing: border-box;
	border-bottom: 2px solid #ffffff00;
}

.swiper-tab .on {
	color: #786cff;
	border-bottom: 2px solid #786cff;
}

/* 设置scroll-view容器高度 */

.widget-list,
.yoshop-notcont {
	height: 100.1%;
}

/* 订单列表 */

.widget-list {
	padding: 10rpx 20rpx 40rpx 20rpx;
	box-sizing: border-box;
}

.widget__detail {
	padding: 20rpx 15rpx;
	box-sizing: border-box;
	font-size: 28rpx;
	border-bottom: 1rpx solid #e7e7e7;
}

.widget__detail .user-avatar {
	margin-right: 16rpx;
}

.widget__detail .user-avatar image {
	display: block;
	width: 100rpx;
	height: 100rpx;
	border: 4rpx solid #fff;
	border-radius: 50%;
}

.widget__detail .user-info {
	height: 100%;
}

.widget__detail .user-info .user-nickName {
	margin-bottom: 8rpx;
}

.widget__detail .detail__money {
	width: 100%;
	margin-bottom: 8rpx;
}
</style>
